<html class="hb-loaded">
 <head> 
  <meta content="telephone=no" name="format-detection" /> 
  <meta content="email=no" name="format-detection" /> 
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type" /> 
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" /> 
  <meta content="yes" name="apple-mobile-web-app-capable" /> 
  <meta content="black" name="apple-mobile-web-app-status-bar-style" /> 
  <title>新增收货地址</title> 
 
  <script src="js/jquery.min.js"></script> 
  <script src="js/bootstrap.min.js"></script> 
  <link rel="stylesheet" href="css/bootstrap.min.css" /> 
  <script src="js/ygop.ajax.client.js"></script> 
  <script src="js/Common.v150812.js"></script> 
  <link rel="stylesheet" href="css/public.v20150930.css" /> 
  <script src="js/layer.m.js"></script> 
  <script src="js/jweixin-1.0.0.js" type="text/javascript"></script> 
  <link rel="stylesheet" href="css/layer.css" /> 




 </head> 
 <body> 
  <link type="text/css" rel="stylesheet" href="css/address.css" /> 
  <input type="hidden" value="1" id="iptType" /> 
  <input type="hidden" id="iptCityId" value="" /> 
  <input type="hidden" id="iptAreaId" value="" /> 
  <div class="wrap" id="divNewAddress"> 
   <form> 
    <div class="input-item"> 
     <div class="input-item-list"> 
      <input type="text" placeholder="收货人姓名" id="iptName" /> 
     </div> 
     <div class="input-item-list"> 
      <input type="text" placeholder="手机号码" id="iptMobile" /> 
     </div> 
     <div class="input-item-list selectwrap"> 
      <select onchange="bindCity(this)" name="provinceId" id="sltProvince"><option value="">请选择省份</option><option grade="3" value="312d0556-0671-4f2e-8bac-7b8873b5a03a">上海</option><option grade="3" value="eabbe02f-59e0-46e6-90e7-cd8a89dbb98f">北京</option><option grade="3" value="93570b8c-0a0a-4818-8317-75a0d14093a5">天津</option><option grade="3" value="62024572-439c-46e2-816e-37f52534ef2d">安徽</option><option grade="3" value="15b6c4e6-69f2-4001-a631-62c0c36102b1">北京(郊区)</option><option grade="3" value="a3fd1ee3-6ac7-4161-9393-565fc875aa2b">福建</option><option grade="3" value="69f262ff-cf4f-4920-a10a-7880e27dd440">甘肃</option><option grade="3" value="d0f11a9b-602c-498e-ab10-685f4c551d3d">广东</option><option grade="3" value="e615d764-bdd3-4758-913a-59ed8503a5de">广西</option><option grade="3" value="ebe771a5-36fb-4116-a98f-7afb5290b334">贵州</option><option grade="3" value="1b1bd95f-7fd4-4f6e-9e3a-340b1f6c3cc5">海南</option><option grade="3" value="da114907-9426-421c-a710-9d319e6a67fd">河北</option><option grade="3" value="8253d296-8c94-4935-87f6-8a61cd8a9cf3">河南</option><option grade="3" value="1935e31f-5600-48cd-9550-054a0a7c44ce">黑龙江</option><option grade="3" value="a6804a4e-e46c-4121-b964-fcf80db3bf74">湖北</option><option grade="3" value="64c4d7d4-e511-425e-ad09-03defd808faf">湖南</option><option grade="3" value="7b98f60b-bf6b-414a-a1a4-fec9ef121b5f">吉林</option><option grade="3" value="75ff9dce-aba7-4dce-a40d-d70ed77a1d22">江苏</option><option grade="3" value="55584cd4-e249-4cd8-9895-462e637e463e">江西</option><option grade="3" value="322e0992-f6ea-426d-9794-a5fac5e91adf">辽宁</option><option grade="3" value="78e4e930-5c94-4cd8-b3b9-1cbc0963efa6">内蒙古</option><option grade="3" value="76ba776c-a7df-44f8-8932-4a5a95eef734">宁夏</option><option grade="3" value="8ce3d107-f0d0-42c3-bbcd-a03463fbe1f3">青海</option><option grade="3" value="8ba9f215-379f-451d-893b-0ac3fb6b1f52">山东</option><option grade="3" value="e1071724-bdbf-4947-becd-64621f189676">山西</option><option grade="3" value="8dce2e33-92de-4e38-86b8-be3e4165cca9">陕西</option><option grade="3" value="98373b1b-201c-4753-b540-14bb1cd6564e">上海(郊区)</option><option grade="3" value="09806a8f-dee4-46f6-9682-af8fb426d0e7">四川</option><option grade="3" value="b9c713c2-aa5f-4aa3-9d26-a3494c95e739">西藏</option><option grade="3" value="693c737b-d014-4572-8c80-17ecf4bafd98">新疆</option><option grade="3" value="7d975a49-01ff-4a74-accf-e0ef2f5bddac">云南</option><option grade="3" value="de66faa1-cb91-4af7-a6c9-3269f9f9e169">浙江</option><option grade="3" value="7c046210-81f3-4638-a09b-6b2e8ecbe957">重庆</option></select> 
      <div class="arrowwrap"> 
       <em class="arrow"> </em> 
      </div> 
     </div> 
     <div class="input-item-list selectwrap"> 
      <select onchange="bindArea(this)" id="sltCity" name="cityId"><option value="">请选择城市</option><option grade="4" value="c8d9363c-fc0a-4f7b-9a18-3aedbbc83e57">昌平区</option><option grade="4" value="fec982f5-acae-47cb-8bb5-b6aa2dea9be7">朝阳区</option><option grade="4" value="f98f6270-b785-4477-be2a-e7700d67b05b">崇文区</option><option grade="4" value="7c4270dd-ccaf-4d55-bdc7-2c6f961075fe">大兴区</option><option grade="4" value="2d426e4a-fb5c-41f1-adf1-df141b302ef5">东城区</option><option grade="4" value="b68b0e34-fbb0-4153-9f8b-df1f2e9dad51">房山区</option><option grade="4" value="70baf2c9-46d6-45ec-ab49-a4c43626cf43">丰台区</option><option grade="4" value="573acdc8-561d-4171-9155-12be84061b18">海淀区</option><option grade="4" value="d4f59efd-e53a-488e-a9f5-1e9d209e9201">门头沟区</option><option grade="4" value="c3757b2e-da8e-4eb6-9f56-1c90e48c4d55">石景山区</option><option grade="4" value="221aadc5-58a9-4725-851f-af0474aaac97">顺义区</option><option grade="4" value="4e82b9f5-0721-49b3-ab9b-2d1f6b4d6b63">通州区</option><option grade="4" value="e49a5017-2767-4161-9e43-8cd146e929e1">西城区</option><option grade="4" value="15d5e691-7dd0-45f7-8cad-1622a20e3209">宣武区</option><option grade="4" value="95869d1f-594d-4027-8cf4-a8ef043e1d95">燕郊</option></select> 
      <div class="arrowwrap"> 
       <em class="arrow"> </em> 
      </div> 
     </div> 
     <div class="input-item-list selectwrap"> 
      <select id="sltArea" name="areaId"><option value="">请选择区</option><option grade="5" value="70a9d9c0-b430-411c-a147-3575b08516b2">崇文区</option></select> 
      <div class="arrowwrap"> 
       <em class="arrow"> </em> 
      </div> 
     </div> 
     <div class="input-item-list"> 
      <input type="text" placeholder="详细地址" id="iptAddressDetails" /> 
     </div> 
    </div> 
    <div class="input-item mt20"> 
     <div class="default-input"> 
      <input type="checkbox" id="default" name="" /> 
      <label for="default">是否设为默认地址</label> 
     </div> 
    </div> 
    <div id="btn" class="btn-submit"> 
     <span style="width: 100%;"><button onclick="saveAddress();" type="button" id="btnsave">保存</button></span> 
    </div> 
   </form> 
  </div> 
  <script type="text/javascript">
    var _type = "selectadd";
    var _consigneeId = "add";
    var _returnUrl = "";

    $(function () {
        if (_type == "edit") {
            document.title = "编辑收货地址";
            $("#btn").append("<span><button  class=\"bggray\" type=\"button\" onclick=\"delConfirm(); \">删除</button></span>");

            //绑定省份信息
            bindProvince();
        }
        else if (_type == "selectedit") {
            document.title = "编辑收货地址";
            $("#btnsave").parent().css("width", "100%");

            //绑定省份信息
            bindProvince();
        }
        else {
            document.title = "新增收货地址";
            $("#btnsave").parent().css("width", "100%");

            //清空地址信息
            clearNewAddressInfo();
        }
    })

    //获取省份信息
    function bindProvince() {
        bindArealist("", "", $("#sltProvince"), null, initData);
    }

    //获取地址信息
    function initData() {
        var consigneeId = _consigneeId;
//        YgmJsCommon.popups.loading();
    }

    //绑定城市信息
    function bindUpdateAddressCity() {
        $("#sltCity").val($("#iptCityId").val());
        bindArea($("#sltCity"), bindUpdateAddressArea);
    }

    //绑定区县信息
    function bindUpdateAddressArea() {
        $("#sltArea").val($("#iptAreaId").val());
    }

    //保存地址信息
    function saveAddress() {
        var name = $.trim($("#iptName").val());
        if (name == "") {
            YgmJsCommon.popups.alert("用户名不能为空！");
            $("#iptName").focus();
            return;
        }
        var mobile = $.trim($("#iptMobile").val());
        if (mobile == "") {
            YgmJsCommon.popups.alert("手机号码不能为空！");
            $("#iptMobile").focus();
            return;
        }
        if (isNaN(mobile) || mobile.length != 11) {
            YgmJsCommon.popups.alert("手机号码格式不正确！");
            $("#iptMobile").focus();
            return;
        }
        var province = $.trim($("#sltProvince").find("option:selected").val());
        if (province == "") {
            YgmJsCommon.popups.alert("请选择省份！");
            $("#sltProvince").focus();
            return;
        }
        var city = $.trim($("#sltCity").find("option:selected").val());
        if (city == "") {
            YgmJsCommon.popups.alert("请选择城市！");
            $("#sltCity").focus();
            return;
        }
        var area = $.trim($("#sltArea").find("option:selected").val());
        if (area == "") {
            YgmJsCommon.popups.alert("请选择地区！");
            $("#sltArea").focus();
            return;
        }
        var addressDetails = $.trim($("#iptAddressDetails").val());
        if (addressDetails == "") {
            YgmJsCommon.popups.alert("地址详情不能为空！");
            $("#iptAddressDetails").focus();
            return;
        }
        if ($("#default").is(':checked') == true) {
            var defaulte = 1;
        }
        else {
            var defaulte = 0;
        }
        var action = $("#iptType").val();
        var consigneeId = _consigneeId;
        var data = {};
        data.ConsigneeName = name;
        data.ProvinceId = province;
        data.DistrictId = area;
        data.AreaId = city;
        data.AddressDetails = addressDetails;
        data.ConsigneeMobile = mobile;
        data.IsDefault = defaulte;
        var type = _type;
        if (action == 1) {
            YgmJsCommon.popups.loading();
            ygopAjaxClient.async("/AddressOpt/InsertConsigneeInfo", "post", data, function (e) {
                YgmJsCommon.popups.close();
                if (e.RspCode == 1) {
                    if (type == "add") {
                        YgmJsCommon.popups.tag(e.RspMsg, null, backHistory);
                    }
                    else {
                        backSettle(e.RspData.data.ConsigneeId);
                    }
                }
                else {
                    YgmJsCommon.popups.alert(e.RspMsg);
                }
            });
        }
        if (action == 2) {
            data.ConsigneeId = consigneeId;
            YgmJsCommon.popups.loading();
            ygopAjaxClient.async("/AddressOpt/UpdateConsigneeInfo", "post", data, function (e) {
                YgmJsCommon.popups.close();
                if (e.RspCode == 1) {
                    if (type == "edit") {
                        YgmJsCommon.popups.tag(e.RspMsg, null, backHistory);
                    }
                    else {
                        backSettle(e.RspData.data.ConsigneeId);
                    }
                }
                else {
                    YgmJsCommon.popups.alert(e.RspMsg);
                }
            });
        }
    }

    //获取省市区信息
    function bindArealist(pId, grade, sltArea, areaInfo, callback) {
   
    }

    //绑定城市
    function bindCity(sltProvince, callback) {
        var pID = $(sltProvince).find("option:selected").val();
        var grade = $(sltProvince).find("option:selected").attr("grade");
        clearCityInfo($("#sltCity"));
        if (pID != "" && pID != null) {
            bindArealist(pID, grade, $("#sltCity"), "<option value=\"\">请选择城市</option>", callback);
        }
        clearCityInfo($("#sltArea"));
    }

    //绑定区县
    function bindArea(sltCity, callback) {
        var pID = $(sltCity).find("option:selected").val();
        var grade = $(sltCity).find("option:selected").attr("grade");
        clearCityInfo($("#sltArea"));
        if (pID != "" && pID != null) {
            bindArealist(pID, grade, $("#sltArea"), "<option value=\"\">请选择区</option>", callback);
        }
    }

    //清空地址信息
    function clearNewAddressInfo() {
        $("#iptName").val("");
        $("#iptMobile").val("");
        $("#iptAddressDetails").val("");
        bindArealist("", "", $("#sltProvince"), "<option value=\"\">请选择省份</option>");
        $("#iptCityId").val("");
        $("#iptAreaId").val("");
        $("#iptConsigneeId").val("");
    }

    //删除地址信息
    function deleteAddress() {
        var consigneeId = _consigneeId;
        YgmJsCommon.popups.loading();
        ygopAjaxClient.async("/AddressOpt/DeleteConsigneeInfo", "post", { "ConsigneedId": consigneeId }, function (e) {
            YgmJsCommon.popups.close();
            if (e.RspCode == 1) {
                YgmJsCommon.popups.tag(e.RspMsg, null, backHistory);
            }
            else {
                YgmJsCommon.popups.alert(e.RspMsg);
            }
        });
    }

    //删除地址确认
    function delConfirm() {
        YgmJsCommon.popups.confirm("确定删除地址吗?", deleteAddress);
    }

    //返回上级地址
    function backHistory() {
        location.href = document.referrer;
    }

    //返回结算页
    function backSettle(cid) {
        var consigneeId = cid;
        YgmJsCommon.popups.loading();
        ygopAjaxClient.async("/SettleOpt/ChooseAddress", "post", { consigneeId: consigneeId }, function (e) {
            YgmJsCommon.popups.close();
            if (e.RspCode == 1) {
                if (_returnUrl == undefined || _returnUrl == null || _returnUrl == "") {
                    location.href = "/settle";
                }
                else {
                    location.href = _returnUrl;
                }
            }
            else {
                YgmJsCommon.popups.alert(e.RspMsg);
            }
        });
    }

    //清空省市信息
    function clearCityInfo(sltArea) {
        sltArea.empty();
        var option = "";
        option += "<option value=\"\">请选择区</option>";
        sltArea.html(option);
        sltArea.get(0).selectedIndex = 0;
    }
</script> 
  <script type="text/javascript">
    var _wx_JsConfig = {};
    _wx_JsConfig.appid = "wx0d4f4f0e0bada80e";
    _wx_JsConfig.imgUrl = "http://img02.yiguo.com/e/web/150930/00783/155744/wxlogo.jpg";
    _wx_JsConfig.title = "易果生鲜触屏版";
    _wx_JsConfig.content = "全国首家生鲜专业电商，全球优质生鲜产地直供，全年无休生鲜冷链配送";
    _wx_JsConfig.timeLineLink = "http://weixin.m.yiguo.com";

    _wx_JsConfig.timestamp = "";
    _wx_JsConfig.nonceStr = "";
    _wx_JsConfig.signature = "";

    $(function () {
        YgmJsCommon.domain = "yiguo.com";

        var jsonWxCfg = decodeURIComponent("%7b%22appId%22%3anull%2c%22timestamp%22%3a%221445765555%22%2c%22nonceStr%22%3a%221309023915%22%2c%22signature%22%3a%225c8a1b9ff5d71bfe6e50ede171330ee60cd37348%22%2c%22url%22%3a%22http%3a%2f%2fweixin.m.yiguo.com%2fHome%2fAddress%3ftype%3dselectadd%26passKey%3d5aebb82bd99013f38d57daa170edf56a%22%2c%22jsapi_ticket%22%3a%22bxLdikRXVbTPdHSM05e5u_n3yqdZ_9Pt0dvnbtzvrXZ2Bps91PjRajJdScVYkXWafhoi6zfSwxWok0rXn11cmQ%22%7d");
        var wxJsCfg = JSON.parse(jsonWxCfg);
        _wx_JsConfig.timestamp = wxJsCfg.timestamp;
        _wx_JsConfig.nonceStr = wxJsCfg.nonceStr;
        _wx_JsConfig.signature = wxJsCfg.signature;

        wx.config({
            //debug: true,
            appId: _wx_JsConfig.appid,
            timestamp: _wx_JsConfig.timestamp,
            nonceStr: _wx_JsConfig.nonceStr,
            signature: _wx_JsConfig.signature,
            jsApiList: [
                'onMenuShareTimeline',
                'onMenuShareAppMessage'
            ]
        });

        myShare();
    });

    function myShare() {
        wx.ready(function () {
            //分享朋友圈
            wx.onMenuShareTimeline({
                title: _wx_JsConfig.title,
                desc: _wx_JsConfig.content, // 分享描述
                link: _wx_JsConfig.timeLineLink,
                imgUrl: _wx_JsConfig.imgUrl,
                trigger: function (res) {
                },
                success: function (res) {
                    dplus.track("分享到朋友圈");
                },
                cancel: function (res) {
                },
                fail: function (res) {
                }
            });
            //分享朋友
            wx.onMenuShareAppMessage({
                title: _wx_JsConfig.title,
                desc: _wx_JsConfig.content,
                link: _wx_JsConfig.timeLineLink,
                imgUrl: _wx_JsConfig.imgUrl,
                trigger: function (res) {
                },
                success: function (res) {
                    dplus.track("分享给朋友");
                },
                cancel: function (res) {
                },
                fail: function (res) {
                }
            });
        });

    }

    window.onload = function () {
        
    };
</script>
 </body>
</html>